package dk.dlug.platform.model;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;


@Repository
public class BoardModel {

	@Inject
	@Named("sqlMapClientTemplate")
	private SqlMapClientTemplate sqlMapClientTemplate;
	
	public List<HashMap> getList(){
		System.out.println("CalendarModel getSchedule Call.");
		
		 SimpleDateFormat new_format = new SimpleDateFormat("yyyy-MM-dd");
		
		ArrayList<HashMap> tempList = new ArrayList<HashMap>();
		tempList  = (ArrayList<HashMap>)sqlMapClientTemplate.queryForList("getList");
		Date tempDate = null;
		String newDate = null;
		
		for(HashMap<String,Object> temp : tempList){
			tempDate = (Date) temp.get("regDate");
			newDate = new_format.format(tempDate);
			System.out.println(newDate);
			temp.put("regDate",newDate);
		}
		
		return tempList;
	}
	
	public void addEvent(Map<String,Object> params) throws Exception{
		sqlMapClientTemplate.insert("addEvent",params);
	}
}
